using System;
using System.Collections.Generic;

namespace RxjhServer
{
	public class DropClass
	{
		private int _FLD_NPC;

		private int _FLD_LEVEL1;

		private int _FLD_LEVEL2;

		private int _FLD_PID;

		private int _FLD_PP;

		public int FLD_MAGICNew0;

		public int FLD_MAGICNew1;

		public int FLD_MAGICNew2;

		public int FLD_MAGICNew3;

		public int FLD_MAGICNew4;

		private int _FLD_NJ;

		private int _FLD_MAGIC0;

		private int _FLD_MAGIC1;

		private int _FLD_MAGIC2;

		private int _FLD_MAGIC3;

		private int _FLD_MAGIC4;

		private string _FLD_NAME;

		private int _是否提示;

		private int _需要金符;

		public static object AsyncLock = new object();

		public static object AsyngLock = new object();

		public static object AsynbLock = new object();

		private int _id;

		private int _ID;

		public int id
		{
			get
			{
				return _id;
			}
			set
			{
				_id = value;
			}
		}

		public int ID
		{
			get
			{
				return _ID;
			}
			set
			{
				_ID = value;
			}
		}

		public int FLD_NPC
		{
			get
			{
				return _FLD_NPC;
			}
			set
			{
				_FLD_NPC = value;
			}
		}

		public int FLD_LEVEL1
		{
			get
			{
				return _FLD_LEVEL1;
			}
			set
			{
				_FLD_LEVEL1 = value;
			}
		}

		public int FLD_LEVEL2
		{
			get
			{
				return _FLD_LEVEL2;
			}
			set
			{
				_FLD_LEVEL2 = value;
			}
		}

		public int FLD_PID
		{
			get
			{
				return _FLD_PID;
			}
			set
			{
				_FLD_PID = value;
			}
		}

		public int FLD_PP
		{
			get
			{
				return _FLD_PP;
			}
			set
			{
				_FLD_PP = value;
			}
		}

		public int FLD_NJ
		{
			get
			{
				return _FLD_NJ;
			}
			set
			{
				_FLD_NJ = value;
			}
		}

		public int FLD_MAGIC0
		{
			get
			{
				return _FLD_MAGIC0;
			}
			set
			{
				_FLD_MAGIC0 = value;
			}
		}

		public int FLD_MAGIC1
		{
			get
			{
				return _FLD_MAGIC1;
			}
			set
			{
				_FLD_MAGIC1 = value;
			}
		}

		public int FLD_MAGIC2
		{
			get
			{
				return _FLD_MAGIC2;
			}
			set
			{
				_FLD_MAGIC2 = value;
			}
		}

		public int FLD_MAGIC3
		{
			get
			{
				return _FLD_MAGIC3;
			}
			set
			{
				_FLD_MAGIC3 = value;
			}
		}

		public int FLD_MAGIC4
		{
			get
			{
				return _FLD_MAGIC4;
			}
			set
			{
				_FLD_MAGIC4 = value;
			}
		}

		public string FLD_NAME
		{
			get
			{
				return _FLD_NAME;
			}
			set
			{
				_FLD_NAME = value;
			}
		}

		public int 是否提示
		{
			get
			{
				return _是否提示;
			}
			set
			{
				_是否提示 = value;
			}
		}

		public int 需要金符
		{
			get
			{
				return _需要金符;
			}
			set
			{
				_需要金符 = value;
			}
		}

		public DropClass()
		{
			FLD_NPC = 0;
			FLD_LEVEL1 = 0;
			FLD_LEVEL2 = 0;
			FLD_PID = 0;
			FLD_PP = 0;
			FLD_MAGICNew0 = 0;
			FLD_MAGICNew1 = 0;
			FLD_MAGICNew2 = 0;
			FLD_MAGICNew3 = 0;
			FLD_MAGICNew4 = 0;
			FLD_NJ = 0;
			FLD_MAGIC0 = 0;
			FLD_MAGIC1 = 0;
			FLD_MAGIC2 = 0;
			FLD_MAGIC3 = 0;
			FLD_MAGIC4 = 0;
			FLD_NAME = "";
			需要金符 = 0;
		}

		public static List<DropClass> GetBossDrop(int leve, int npcid)
		{
			using (new Lock(AsynbLock, "Boss怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				List<DropClass> list2 = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 10000);
				foreach (DropClass item in World.BossDrop)
				{
					if (item.FLD_NPC != 0)
					{
						if (item.FLD_NPC == npcid && item.FLD_PP > num)
						{
							list.Add(item);
						}
						else if (item.FLD_LEVEL1 <= leve && item.FLD_LEVEL2 >= leve && item.FLD_PP >= num)
						{
							list.Add(item);
						}
					}
					else if (item.FLD_LEVEL1 <= leve && item.FLD_LEVEL2 >= leve && item.FLD_PP >= num)
					{
						list.Add(item);
					}
				}
				if (list.Count == 0)
				{
					return null;
				}
				string[] array = World.BOSS怪随机掉落物品数量.Split(';');
				int num2 = random.Next(int.Parse(array[0]), int.Parse(array[1]));
				int num3 = 0;
				foreach (DropClass item2 in list)
				{
					if (num3 >= num2)
					{
						break;
					}
					int index = random.Next(0, list.Count);
					list2.Add(list[index]);
					num3++;
				}
				if (list2.Count == 0)
				{
					return null;
				}
				return list2;
			}
		}

		public static List<DropClass> GetGSDrop(int leve, int sl, int maxsl, int npcid)
		{
			using (new Lock(AsyngLock, "高手怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				List<DropClass> list2 = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 10000);
				foreach (DropClass drop_G in World.Drop_GS)
				{
					if (drop_G.FLD_NPC != 0)
					{
						if (drop_G.FLD_NPC == npcid && drop_G.FLD_PP > num)
						{
							list.Add(drop_G);
						}
					}
					else if (drop_G.FLD_LEVEL1 <= leve && drop_G.FLD_LEVEL2 >= leve && drop_G.FLD_PP >= num)
					{
						list.Add(drop_G);
					}
				}
				if (list.Count == 0)
				{
					return null;
				}
				int num2 = random.Next(sl, maxsl);
				int num3 = 0;
				foreach (DropClass item in list)
				{
					if (num3 >= num2)
					{
						break;
					}
					int index = random.Next(0, list.Count);
					list2.Add(list[index]);
					num3++;
				}
				if (list2.Count == 0)
				{
					return null;
				}
				return list2;
			}
		}

		public static DropClass 卖物品(int ID)
		{
			List<DropClass> list = new List<DropClass>();
			long ticks = DateTime.Now.Ticks;
			Random random = new Random();
			foreach (DropClass item in World.Drop)
			{
				if (item.FLD_PID == ID)
				{
					list.Add(item);
				}
			}
			if (list.Count == 0)
			{
				return null;
			}
			int index = random.Next(0, list.Count);
			return list[index];
		}

		public static DropClass GetRwDrop(Players play, int npcid)
		{
			List<DropClass> list = new List<DropClass>();
			Random random = new Random();
			int num = random.Next(0, 8000);
			if (play != null)
			{
				foreach (DropClass item in World.Drop)
				{
					if (item.FLD_NPC == npcid && item.FLD_PP > num && play.检查任务是否匹配(item.FLD_PID))
					{
						list.Add(item);
					}
				}
				if (list.Count > 0)
				{
					int index = random.Next(0, list.Count);
					return list[index];
				}
			}
			return null;
		}

		public static DropClass GetDrop(Players play, int leve, int npcid)
		{
			using (new Lock(AsyncLock, "普通怪物掉落"))
			{
				List<DropClass> list = new List<DropClass>();
				Random random = new Random();
				int num = RNG.Next(0, 10000);
				foreach (DropClass item in World.Drop)
				{
					if (item.FLD_LEVEL1 <= leve && item.FLD_LEVEL2 >= leve && item.FLD_PP >= num)
					{
						if (item.需要金符 == 1)
						{
							if (play.检查金符())
							{
								list.Add(item);
							}
						}
						else if (item.需要金符 == 2)
						{
							if (play.检查银符())
							{
								list.Add(item);
							}
						}
						else if (item.需要金符 == 3)
						{
							if (play.检查公有药品())
							{
								list.Add(item);
							}
						}
						else
						{
							list.Add(item);
						}
					}
				}
				if (list.Count < 1)
				{
					return null;
				}
				int index = random.Next(0, list.Count);
				return list[index];
			}
		}
	}
}
